﻿using System;
using System.Collections.Generic;
using System.Web;

namespace FDeal
{
    public class ChiTietDealBUS
    {
        private ChiTietDealDAO _dDAO;

        public ChiTietDealBUS()
        {
            _dDAO = new ChiTietDealDAO();
        }

        public void Insert(ChiTietDealDTO obj)
        {
            _dDAO.insert(obj);
        }

        public void Insert(string idDeal, string tieude, string loai, string tomtat,
            string hinhanh, float giagoc, string donvi, int giam,
            float giaconlai, int songuoimua, int thoigianconlai, int sodealban,
            string dieukien, string diemnoibat, string diachi, string bando,
            int luotxem, DateTime ngaydang, string nguoidang, string diadiembandeal
            )
        {
            ChiTietDealDTO obj = new ChiTietDealDTO();

            obj.Bando = bando;
            obj.Diachi = diachi;
            obj.Diadiembandeal = diadiembandeal;
            obj.Diemnoibat = diemnoibat;
            obj.Dieukien = dieukien;
            obj.Donvi = donvi;
            obj.Giaconlai = giaconlai;
            obj.Giagoc = giagoc;
            obj.Giam = giam;
            obj.Hinhanh = hinhanh;
            obj.Iddeal = idDeal;
            obj.Loaideal = loai;
            obj.Luotxem = luotxem;
            obj.Ngaydang = ngaydang;
            obj.Nguoidang = nguoidang;
            obj.Sodealban = sodealban;
            obj.Songuoimua = songuoimua;
            obj.Thoigianconlai = thoigianconlai;
            obj.Tieude = tieude;
            obj.Tomtatdeal = tomtat;

            this.Insert(obj);
        }

        public void Delete(string idDeal)
        {
            _dDAO.delete(idDeal);
        }

        public void Update(ChiTietDealDTO obj)
        {
            _dDAO.update(obj);
        }

        public ChiTietDealDTO[] GetDsChiTietDeal()
        {
            return _dDAO.getDsChiTietDeal();
        }

        public ChiTietDealDTO GetChiTietDeal(string idDeal)
        {
            ChiTietDealDTO[] ds = this.GetDsChiTietDeal();

            for (int i = 0; i < ds.Length; i++)
            {
                if (ds[i].Iddeal.Equals(idDeal))
                    return ds[i];
            }
            return null;
        }
    }
}
